/**
 *
 */
package com.typhoon.spring_shiro.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author hujun
 */
public class ThreadPoolUtils {

    private static ExecutorService executorService;

    private static final int CORE_SIZE  = 30;
    private static final int MAX_SIZE   = 50;
    private static final int QUEUE_SIZE = 10000;

    static {
        executorService = new ThreadPoolExecutor(CORE_SIZE, MAX_SIZE, 30L, TimeUnit.SECONDS,
                                                 new ArrayBlockingQueue<Runnable>(QUEUE_SIZE), new ThreadPoolExecutor.DiscardOldestPolicy());
    }

    /**
     * 提交任务
     *
     * @param runable
     */
    public static void execute(Runnable runable) {
        executorService.execute(runable);
    }

    public static <T> Future<T> submit(Callable<T> callable) {
        return executorService.submit(callable);
    }

    public static Future<?> submit(Runnable runable) {
        return executorService.submit(runable);
    }

    public static void shutdown() {
        executorService.shutdown();
    }
}
